function varargout = compensator(varargin)
% COMPENSATOR MATLAB code for compensator.fig
%      COMPENSATOR, by itself, creates a new COMPENSATOR or raises the existing
%      singleton*.
%
%      H = COMPENSATOR returns the handle to a new COMPENSATOR or the handle to
%      the existing singleton*.
%
%      COMPENSATOR('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in COMPENSATOR.M with the given input arguments.
%
%      COMPENSATOR('Property','Value',...) creates a new COMPENSATOR or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before compensator_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to compensator_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help compensator

% Last Modified by GUIDE v2.5 12-Feb-2025 20:05:28

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @compensator_OpeningFcn, ...
                   'gui_OutputFcn',  @compensator_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before compensator is made visible.
function compensator_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to compensator (see VARARGIN)

% Choose default command line output for compensator
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes compensator wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = compensator_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject    handle to Start (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clc;
gs_num=get(handles.GS_Num,'String');
gs_deno=get(handles.GS_Deno,'String');
hs_num=get(handles.HS_Num,'String');
hs_deno=get(handles.HS_Deno,'String');
axes(handles.axes1); 
set_param('compensator_sim/Transfer_Fcn','Numerator',gs_num);
set_param('compensator_sim/Transfer_Fcn','Denominator',gs_deno);
set_param('compensator_sim/Transfer_Fcn1','Numerator',hs_num);
set_param('compensator_sim/Transfer_Fcn1','Denominator',hs_deno);
sim('compensator_sim');
global time_date;
time_date=system_res;
tout=time_date(:,1);
yout=time_date(:,2);
plot(tout,yout,'b','LineWidth',0.5);
%xlabel('Time');
%ylabel('value');
grid on;
grid minor;

% --- Executes on button press in time_analy_button.
function time_analy_button_Callback(hObject, eventdata, handles)
% hObject    handle to time_analy_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clc;
close(gcf);
main

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clc;
close(gcf);
main


function GS_Num_Callback(hObject, eventdata, handles)
% hObject    handle to GS_Num (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of GS_Num as text
%        str2double(get(hObject,'String')) returns contents of GS_Num as a double
gs_num=str2num(get(handles.GS_Num,'String'));
gs_deno=str2num(get(handles.GS_Deno,'String'));
str_func=show_trans_func(gs_num,gs_deno);
str_func=sprintf('=%s',str_func);
set(handles.GS_Show,'String',str_func);

% --- Executes during object creation, after setting all properties.
function GS_Num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to GS_Num (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function GS_Deno_Callback(hObject, eventdata, handles)
% hObject    handle to GS_Deno (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of GS_Deno as text
%        str2double(get(hObject,'String')) returns contents of GS_Deno as a double
gs_num=str2num(get(handles.GS_Num,'String'));
gs_deno=str2num(get(handles.GS_Deno,'String'));
str_func=show_trans_func(gs_num,gs_deno);
str_func=sprintf('=%s',str_func);
set(handles.GS_Show,'String',str_func);

% --- Executes during object creation, after setting all properties.
function GS_Deno_CreateFcn(hObject, eventdata, handles)
% hObject    handle to GS_Deno (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function HS_Num_Callback(hObject, eventdata, handles)
% hObject    handle to HS_Num (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of HS_Num as text
%        str2double(get(hObject,'String')) returns contents of HS_Num as a double
hs_num=str2num(get(handles.HS_Num,'String'));
hs_deno=str2num(get(handles.HS_Deno,'String'));
str_func=show_trans_func(hs_num,hs_deno);
str_func=sprintf('=%s',str_func);
set(handles.HS_Show,'String',str_func);

% --- Executes during object creation, after setting all properties.
function HS_Num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to HS_Num (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function HS_Deno_Callback(hObject, eventdata, handles)
% hObject    handle to HS_Deno (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of HS_Deno as text
%        str2double(get(hObject,'String')) returns contents of HS_Deno as a double
hs_num=str2num(get(handles.HS_Num,'String'));
hs_deno=str2num(get(handles.HS_Deno,'String'));
str_func=show_trans_func(hs_num,hs_deno);
str_func=sprintf('=%s',str_func);
set(handles.HS_Show,'String',str_func);

% --- Executes during object creation, after setting all properties.
function HS_Deno_CreateFcn(hObject, eventdata, handles)
% hObject    handle to HS_Deno (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
